from common.base import webdriver, By, sleep

driver = webdriver.Chrome()
driver.maximize_window()
driver.get('https://www.so.com')
driver.find_element(By.ID, 'input').send_keys('python')
driver.find_element(By.ID, 'search-button').click()
# 滑动到底部
sleep(2)
js1 = 'window.scrollTo(0, document.body.scrollHeight)'
driver.execute_script(js1)
sleep(2)
# 到顶部
js2 = 'window.scrollTo(0, 0)'
driver.execute_script(js2)
sleep(2)
# 平滑滑动到底部
js3 = 'window.scrollTo({left:0, top:document.body.scrollHeight, behavior:"smooth"})'
driver.execute_script(js3)
sleep(2)
driver.execute_script(js2)
sleep(2)
# 聚焦到某一位置
target = driver.find_element(By.XPATH, '//*[@id="main"]/ul/li[2]/h3/a')
driver.execute_script("arguments[0].scrollIntoView();", target)

sleep(2)
driver.quit()